package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    
    @Autowired
    private IPermissionService permissionService;


    @RequestMapping("/list")
    @RequiresPermissions(value = {"permission:list","权限列表"},logical = Logical.OR)
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo pageInfo = permissionService.queryForList(qo);
        model.addAttribute("result", pageInfo);
        return "permission/list"; // /WEB-INF/views/permission/list.ftl
    }

    @RequestMapping("/reload")
    @RequiresPermissions(value = {"permission:reload","权限加载"},logical = Logical.OR)
    public String reload(Model model, @ModelAttribute("qo") QueryObject qo){
        permissionService.reload();
        return "redirect:/permission/list.do"; // /WEB-INF/views/permission/list.ftl
    }


}
